//引入路由组件
//import Home from '@/pages/Home';
import Search from '@/pages/Search';
import Login from '@/pages/Login';
import Register from '@/pages/Register';
import Detail from '@/pages/Detail';
import AddCartSuccess from '@/pages/AddCartSuccess';
import ShopCart from '@/pages/ShopCart';
import Trade from '@/pages/Trade';
import Pay from '@/pages/Pay';
import PaySuccess from '@/pages/PaySuccess';
import Center from '@/pages/Center';
//引入二级路由组件
import MyOrder from '@/pages/Center/MyOrder';
import GroupOrder from '@/pages/Center/GroupOrder';


//路由配置信息
export default [
    {
        path: '/center',
        component: Center,
        name: 'center',
        meta: {//路由原信息
            show: true,
        },
        children: [//二级路由组件
            {
                path: 'myorder',
                component: MyOrder,
            }, {
                path: 'grouporder',
                component: GroupOrder,
            }, {
                path: '/center',
                redirect: '/center/myorder',//如果访问的是center路径，就键重定向到/center/myorder
            }
        ]
    }, {
        path: '/paysuccess',
        component: PaySuccess,
        name: 'paysuccess',
        meta: {//路由原信息
            show: true,
        }
    }, {
        path: '/pay',
        component: Pay,
        name: 'pay',
        meta: {//路由原信息
            show: true,
        },
        beforeEnter: (to, from, next) => {
            if (from.path == '/trade') {//去支付页面,必须是从交易页面而来
                next();
            } else {//其他路由组件而来的,停留在当前
                next(false);
            }
        }
    }, {
        path: '/trade',
        component: Trade,
        name: 'trade',
        meta: {//路由原信息
            show: true,
        },
        beforeEnter: (to, from, next) => {
            if (from.path == '/shopcart') {//去交易页面,必须是从购物车而来
                next();
            } else {//其他路由组件而来的,停留在当前
                next(false);
            }
        }
    }, {
        path: '/shopcart',
        component: ShopCart,
        name: 'shopcart',
        meta: {//路由原信息
            show: true,
        }
    }, {
        path: '/addcartsuccess',
        component: AddCartSuccess,
        name: 'addcartsuccess',
        meta: {//路由原信息
            show: true,
        }
    }, {
        path: '/detail/:skuid',
        component: Detail,
        meta: {//路由原信息
            show: true,
        }
    }, {
        path: '/home',
        //对于home组件的路由懒加载,用户访问的时候再加载
        component: () => import("@/pages/Home"),
        meta: {//路由原信息
            show: true,//对于home组件的路由懒加载//对于home组件的路由懒加载
        }
    }, {
        path: '/search/:keyword?',
        name: 'search',
        component: Search,
        meta: {
            show: true,
        },
        //函数写法，传递参数
        props: ($route) => ({
            keyword: $route.params.keyword,
            k: $route.query.k,
        })
    }, {
        path: '/login',
        component: Login,
        meta: {
            show: false,
        }
    }, {
        path: '/Register',
        component: Register,
        meta: {
            show: false,
        }
    },
    //重定向，在项目跑起来的时候，访问"/"或"*",立马让它定向到首页
    //当path值为"/"时,访问的是根；当path值为"*"时,访问的是任意路径
    {
        path: '/',
        redirect: "/home",
    }
]
